home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / DesktopDoubler / Common / Headers / ContextUtils.h next >
Encoding:
C/C++ Source or Header  |  1999-06-22  |  1.5 KB  |  80 lines  |  [TEXT/CWIE]

  1. #ifndef _CONTEXTUTILS_
  2. #define _CONTEXTUTILS_
  3.  
  4. #include <A4Stuff.h>
  5. #include <ConditionalMacros.h>
  6. #include <MacTypes.h>
  7.  
  8.  
  9. #if GENERATING68K && !GENERATINGCFM
  10.     #ifdef __cplusplus
  11.     extern "C" {
  12.     #endif
  13.     
  14.     
  15.     #pragma parameter __D0 GetA4()
  16.     unsigned long GetA4(void) ONEWORDINLINE(
  17.         0x200C);                /*        MOVE.L    A4,D0            */
  18.     
  19.     #pragma parameter __D0 GetA5()
  20.     unsigned long GetA5(void) ONEWORDINLINE(
  21.         0x200D);                /*        MOVE.L    A5,D0            */
  22.     
  23.     #pragma parameter __D0 SwapA4(__D0)
  24.     unsigned long SwapA4(unsigned long) ONEWORDINLINE(
  25.         0xC18C);                /*        EXG        D0,A4            */
  26.     
  27.     #pragma parameter __D0 SwapA5(__D0)
  28.     unsigned long SwapA5(unsigned long) ONEWORDINLINE(
  29.         0xC18D);                /*        EXG        D0,A5            */
  30.     
  31.     #if __A5__
  32.         #pragma parameter __D0 GetCurrentA5()
  33.         extern UInt32 GetCurrentA5(void);
  34.     #endif
  35.     
  36.  
  37.     #ifdef __cplusplus
  38.     }
  39.     #endif
  40. #else
  41.     #define GetA4()                ((UInt32)0)
  42.     #define GetA5()                ((UInt32)0)
  43.     #define SwapA4(x)            ((UInt32)0)
  44.     #define SwapA5(x)            ((UInt32)0)
  45. #endif
  46.  
  47.  
  48. #if GENERATING68K && !GENERATINGCFM
  49.     typedef class GlobalContext
  50.     {
  51.         public:
  52.             #if __A5__
  53.                 UInt32    fOldA5;
  54.             
  55.                 GlobalContext(void) { fOldA5 = SwapA5(GetCurrentA5()); }
  56.                 ~GlobalContext(void) { SwapA5(fOldA5); }
  57.             #else
  58.                 UInt32    fOldA4;
  59.                 
  60.                 GlobalContext(void) { fOldA4 = SetCurrentA4(); }
  61.                 ~GlobalContext(void) { SetA4(fOldA4); }
  62.             #endif
  63.     } GlobalContext;
  64. #else
  65.     typedef UInt32    GlobalContext;
  66. #endif
  67.  
  68.  
  69. typedef class THzContext
  70. {
  71.     public:
  72.         THz        fOldZone;
  73.         
  74.         THzContext(THz zone) { fOldZone = GetZone(); SetZone(zone); }
  75.         ~THzContext(void) { SetZone(fOldZone); }
  76. } THzContext;
  77.  
  78.  
  79. #endif /* _CONTEXTUTILS_ */
  80.